<?php 
$this->load->helper('HTML');
echo link_tag('css/style2.css');?>
<link rel="shortcut icon" href="../images/favicon.ico" type="image/x-icon" />  </head>
<div id="page1">
<div id="wrapper">
    <?php $this->load->view('admin_views/header'); ?><hr />
    <script type="text/javascript">

        //for unit
        $(document).ready( function() {
            $("#intid_unit").autocomplete({
                minLength: 2,
                source:
                    function(req, add){
                    $.ajax({
                        url: "<?php echo base_url(); ?>admin/arisan/lookupUnit",
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result").append(
                   "<input type='hidden' id='id_unit' name='id_unit' value='" + ui.item.id + "' size='10' />"
                );
                },
            });
			
			
			$("#strnama_dealer").autocomplete({
      			minLength: 2,
      			source: 
        		function(req, add){
          			$.ajax({
		        		url: "<?php echo base_url(); ?>admin/arisan/lookupUpline",
		          		dataType: 'json',
		          		type: 'POST',
		          		//data: req,
						data: {
                            term: req.term,
                            state: $('#id_unit').val(),
                           
                        },
						success:    
		            	function(data){
		              		if(data.response =="true"){
		                 		add(data.message);
		              		}
		            	},
              		});
         		},
			select: 
         		function(event, ui) {
            		$("#result").append(
            			"<input type='text' id='strkode_dealer' name='strkode_dealer' value='" + ui.item.id + "'/>"
						"<input type='text' id='strnama_upline' name='strnama_upline' value='" + ui.item.id + "'/>"
					);           		
         		},		
    		});
			
			$("#strnama_upline").autocomplete({
      			minLength: 2,
      			source: 
        		function(req, add){
          			$.ajax({
		        		url: "<?php echo base_url(); ?>admin/arisan/lookupUpline",
		          		dataType: 'json',
		          		type: 'POST',
		          		//data: req,
						data: {
                            term: req.term,
                            state: $('#id_unit').val(),
                           
                        },
						success:    
		            	function(data){
		              		if(data.response =="true"){
		                 		add(data.message);
		              		}
		            	}
              		});
         		},
			});
	    

             
            autoComp();
            autoCompPromo10();
            hut();
            tradein();
            satufreesatu();

        });

        //for barang

        function autoComp(){
           
            //alert($("#chkBox20").attr('checked'));
            if($("#chkBox20").attr('checked') == false){
                var ur = "<?php echo base_url(); ?>admin/penjualan/lookupBarang";
            }else if ($("#chkBox20").attr('checked') == true) {

                var ur = "<?php echo base_url(); ?>admin/penjualan/lookupBarangPromo20";
            }
            $(".id1").autocomplete({

                minLength: 2,
                source:
                    function(req, add){

                    
                    $.ajax({
                         url: ur,
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result1").html(
                    "<input type='text' id='harga_barang' name='harga_barang' value='" + ui.item.value1 + "' size='15' /><input type='hidden' id='id_barang' name='id_barang' value='" + ui.item.id + "' size='15' /><input type='hidden' id='pv' name='pv' value='" + ui.item.value2 + "' size='15' />"
					);
					
                },
            });
            
			
			$(".frees").autocomplete({
                minLength: 2,
                source:
                    function(req, add){

                    //alert(add);
                    $.ajax({
                        url: "<?php echo base_url(); ?>admin/penjualan/lookupBarangFree20",
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result2").html(
                   "<input type='text' id='harga_barang_free' name='harga_barang_free' value='0' size='15' /><input type='hidden' id='id_free' name='id_free' value='" + ui.item.id + "' size='15' />"
                );
                },
            });
             
           
        }

function autoCompPromo10(){

            //alert($("#chkBox20").attr('checked'));
            if($("#chkBox10").attr('checked') == false){
                var ur = "<?php echo base_url(); ?>admin/penjualan/lookupBarang";
            }else if ($("#chkBox10").attr('checked') == true) {

                var ur = "<?php echo base_url(); ?>admin/penjualan/lookupBarangPromo10";
            }
            
            $(".id1").autocomplete({

                minLength: 2,
                source:
                    function(req, add){


                    $.ajax({
                         url: ur,
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result1").html(
                    "<input type='text' id='harga_barang' name='harga_barang' value='" + ui.item.value1 + "' size='15' /><input type='hidden' id='id_barang' name='id_barang' value='" + ui.item.id + "' size='15' /><input type='hidden' id='pv' name='pv' value='" + ui.item.value2 + "' size='15' />"
					);
                },
            });

         
		 $(".frees").autocomplete({
                minLength: 2,
                source:
                    function(req, add){

                    //alert(add);
                    $.ajax({
                        url: "<?php echo base_url(); ?>admin/penjualan/lookupBarangFree10",
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result2").html(
                   "<input type='text' id='harga_barang_free' name='harga_barang_free' value='0' size='15' /><input type='hidden' id='id_free' name='id_free' value='" + ui.item.id + "' size='15' />"
                );
                },
            });
            
		 
        }

    </script>
</div>
<div id="page">
    <div id="page-bgtop">
        <div id="content">
            <div>	<h2 class="title">Arisan</h2>
              <div class="entry">
                <form action="<?php echo base_url()?>admin/arisan/a_risan" method="post" >
              <div id="error"><?php echo validation_errors(); ?></div>
             <table width="685" border="0" id="data" align="center">
  			<tr>
   			<td>
    	<tr>
        <td width="107">&nbsp;</td>
        <td width="316">&nbsp;</td>
        <td width="35">&nbsp;</td>
        <td >&nbsp;<?php //echo $cabang; ?>
              <input type="hidden" name="intid_cabang" size="30" readonly="readonly" value="<?php //echo $id_cabang; ?>">         </td>
         <td>&nbsp;,</td>
         <td>&nbsp;<?php echo date("d-m-Y");?></td>
        </tr>

      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;Unit</td>
        <td>&nbsp;:</td>
        <td><input type="text" name="textfield4" id="intid_unit" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td width="82">&nbsp;Nama</td>
        <td width="7">&nbsp;:</td>
        <td width="213"><input type="text" name="strnama_dealer" id="strnama_dealer" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;No Kartu</td>
        <td>&nbsp;:</td>
        <td valign="top">&nbsp;<div id="result"></div></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;Upline</td>
        <td>&nbsp;:</td>
        <td><div id="result"></div></td>
      </tr>
      
      <tr>
        <td>&nbsp;Group</td>
        <td>&nbsp;
          <select name="group">
                <option value="1" >1</option>
		<option value="2" >2</option>
		<option value="3" >3</option>
                <option value="4" >4</option>
		<option value="5" >5</option>
		<option value="6" >6</option>
                <option value="7" >7</option>
		<option value="8" >8</option>
		<option value="9" >9</option>
                <option value="10" >10</option>
		<option value="11" >11</option>
		<option value="12" >12</option>
                <option value="13" >13</option>
		<option value="14" >14</option>
		<option value="15" >15</option>
          </select></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;Jenis Arisan</td>
        <td>&nbsp;<input name="intcicilan" type="radio" value="5" checked />5 X<input name="intcicilan" type="radio" value="7"/>7 X</td>
        <td colspan="3">Komisi</td>
        <td>&nbsp;<input name="intkomisi" type="radio" value="10" checked />10%<input name="intkomisi" type="radio" value="20"/>20%</td>
      </tr>
      <tr>
        <td colspan="6">&nbsp;
          <div align="center" id="title"></div></td>
        </tr>
      <tr>
        <td colspan="6"><table width="661" border="1" id="data" align="center">
  <tr>
    <td width="127">&nbsp;Silahkan ketik</td>
    <td width="213">&nbsp;Nama Barang</td>
    <td width="177">Harga</td>
    <td width="169" rowspan="3"><div id="data">
        <input type="button" id="addBrg" name="addBrg" value="Tambah" />
        </div>    </td>
  </tr>
  <tr>
    <td>&nbsp;Pilih Barang -&gt;
        <input type="hidden" name="barang[1][intquantity]" id="jumlah" size="5" /></td>
    <td>&nbsp;
        <input type="text" name="barang[1][intid_barang]" class="id1" size="30" /></td>
    <td>&nbsp;
        <div id="result1"></div></td>
    </tr>
  <tr>
    <td>&nbsp;Pilih Barang Free -&gt;</td>
    <td>&nbsp;&nbsp;<input type="text" name="free" class="frees" size="30" disabled  /></td>
    <td>&nbsp;<div id="result2"></div></td>
    </tr>
  <tr>
    <td colspan="4">
      <div id="ButtonAdd" style="margin-left: 150px"></div></td>
  </tr>
</table></td>
        </tr>
      <tr>
        <td colspan="6">
            UM<input type="checkbox" name="intuang_muka" />
            C1<input type="checkbox" name="intc_1" />
            C2 <input type="checkbox" name="intc_2" />
            C3 <input type="checkbox" name="intc_3" />
            C4 <input type="checkbox" name="intc_4" />
            C5 <input type="checkbox" name="intc_5" />
            C6 <input type="checkbox" name="intc_6" />
            C7 <input type="checkbox" name="intc_7" /></td>
        </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
       <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>Omset</td>
        <td>&nbsp;:</td>
        <td><input type="text" name="jumlah" id="intjumlah"/></td>
      </tr>
       <tr>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
         <td>PV</td>
         <td>:</td>
         <td><input type="text" name="intpv" id="intpv"/></td>
       </tr>
       <tr>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
         <td>Komisi 20%</td>
         <td>:</td>
         <td><input type="text" name="komisi2" id="komisi2"/></td>
       </tr>
       <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>Komisi 10%</td>
        <td>:</td>
        <td><input type="text" name="komisi1" id="komisi1"/></td>
      </tr>
       <tr>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
         <td>&nbsp;</td>
         <td>Total Bayar</td>
         <td>:</td>
         <td><input type="text" name="totalbayar" id="totalbayar" />
             <input type="hidden" name="totalbayar1" id="totalbayar1" />
             <input type="hidden" name="totalbayar2" id="totalbayar2" />         </td>
       </tr>
       <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>Cash</td>
        <td>&nbsp;:</td>
        <td><input type="text" name="intcash" id="intcash" onkeyUp="return sisa();"/></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>Debit</td>
        <td>&nbsp;:</td>
        <td><input type="text" name="intdebit" id="intdebit" onkeyUp="return sisa();"/></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>Kartu Kredit</td>
        <td>&nbsp;:</td>
        <td><input type="text" name="intkkredit" id="intkkredit" onkeyUp="return sisa();"/></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;Sisa</td>
        <td>&nbsp;:</td>
        <td><input type="text" name="intsisa" id="intsisa" /></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td colspan="2">&nbsp;&nbsp;<input type="submit" value="Simpan" class="button"/></td>
        <td>&nbsp;</td>
        <td><input class="button" type="button" value="Cancel" onclick="location.href='penjualan';"/></td>
      </tr>
    </table>
             </td>
  </tr>
</table>
</form>
</div>
            </div></div>
    </div>
    <!-- end #content -->
    <?php $this->load->view('admin_views/sidebar_penjualan'); ?><!-- end #sidebar -->
    <div style="clear: both;">&nbsp;</div>
</div>
</div>
<!-- end #page -->
<div id="footer-bgcontent">
    <?php $this->load->view('admin_views/footer'); ?></div>
<script type="text/javascript">
    function sisa()
    {
       if($('#intcash').val() == ""){
            var a = 0;
        }else{
            var a = parseInt($('#intcash').val());
        }
		if($('#intkkredit').val() == ""){
            var b = 0;
        }else{
            var b = parseInt($('#intkkredit').val());
        }
		if($('#intdebit').val() == ""){
            var c = 0;
        }else{
            var c = parseInt($('#intdebit').val());
        }
        var d = parseInt(document.getElementById('totalbayar').value);
        var t = a + b + c;
        var sisa = d - t;
        document.getElementById('intsisa').value = sisa;
    }

     $('#frmjual').submit(function(event){
        
        if($("#intid_unit").val()==""){
            alert('Unit tidak Boleh Kosong!');
            $("#intid_unit").focus();
            event.preventDefault();
        }

        if($("#intjumlah").val()==""){
            alert('Belum ada Transaksi Barang!');
            event.preventDefault();
        }

        if($("#totalbayar").val()==""){
            alert('Belum ada Transaksi Barang!');
            event.preventDefault();
        }

        if($("#intid_jpenjualan").val()==""){
            alert('Anda Belum Memilih Jenis Penjualan!');
            event.preventDefault();
        }
        
    });


    var idx = 1;
    
    $('#addBrg').bind('click', function(e){
       // $("#free").attr("disabled","disabled");
		if($(".id1").val()==""){
            alert('Anda belum memilih barang!');

        }else{

            var brg = $('.id1').val();
            var jumlah = $('#jumlah').val();
            var harga = $('#harga_barang').val();
            var id_barang =  $('#id_barang').val();
			var pv =  $('#pv').val();
            var total = jumlah * harga;
            var out = '';
            out += 'Banyaknya<br>';
            out += '<input id="'+idx+'" name="barang['+idx+'][intquantity]" type="text" size="2" value="'+jumlah+'" onkeyUp="kali(this.id)"  />&nbsp;';
            out += '<input name="barang['+idx+'][intid_barang]" type="text" size="30" value="'+brg+'"  />';
            out += '&nbsp;Harga:&nbsp;<input id="harga_'+idx+'" name="barang['+idx+'][intid_harga]" type="text" size="8" value="'+harga+'">';
            out += '&nbsp;PV:&nbsp;<input id="pv_'+idx+'" name="pv['+idx+'][intpv]" type="text" size="8" value="'+pv+'">';
            out += '&nbsp;Total:&nbsp;<input id="total_'+idx+'" name="barang['+idx+'][intid_total]" type="text" size="8" value="'+total+'">';
            out += '<input name="barang['+idx+'][intid_id]" type="hidden" value="'+id_barang+'">';
            out += ' <a href="#hapus" class="delRow" onclick="$(this).parent().remove()">hapus</a> ';
            out = '<div style="height:60px">' + out + '</div>';
            $(out).insertBefore('#ButtonAdd');
            idx++;
            $('.id1').val('');
            $('#jumlah').val('');
            $('#harga_barang').val('');
			$('#pv').val('');
           }
           //alert($('.frees').val());
			//barangfree
			//if ($('.frees').attr("disabled","")==true)
            if($('.frees').val() != "")
			{
				var brg = $('.frees').val();
				var jumlah = $('#jumlah').val();
				var harga = $('#harga_barang_free').val();
				var id_barang =  $('#id_free').val();
				var pv =  $('#pv').val();
				var total = jumlah * harga;
				var out = '';
				out += 'Banyaknya<br>';
				out += '<input id="'+idx+'" name="barang['+idx+'][intquantity]" type="text" size="2" value="'+jumlah+'" onkeyUp="kali(this.id)"  />&nbsp;';
				out += '<input name="barang['+idx+'][intid_barang]" type="text" size="30" value="'+brg+'"  />';
				out += '&nbsp;Harga:&nbsp;<input id="harga_'+idx+'" name="barang['+idx+'][intid_harga]" type="text" size="8" value="'+harga+'">';
				out += '&nbsp;Total:&nbsp;<input id="total_'+idx+'" name="barang['+idx+'][intid_total]" type="text" size="8" value="'+total+'">';
				out += '<input name="barang['+idx+'][intid_id]" type="hidden" value="'+id_barang+'">';
				out += ' <a href="#hapus" class="delRow" onclick="$(this).parent().remove()">hapus</a> ';
				out = '<div style="height:60px">' + out + '</div>';
				$(out).insertBefore('#ButtonAdd');
				idx++;
				$('.frees').val('');
                $('#harga_barang_free').val('');
				$('#jumlah').val('');
				$('#harga_barang').val('');
            }
			return false;
        
    });

    function kali(id){
        var jml=0;
		var pivi=0;
		for(var i=1; i<= parseFloat(id);i++){

            var jumlah = $('#'+ i).val();
			var harga = parseInt($('#harga_' + i).val());
			var pv = parseFloat($('#pv_' + i).val());
			var tot = jumlah * harga;
			var jmlpv = jumlah * pv;
			
            $('#total_' + i).val(tot);

			if($('#' + i).val() != ""){
                jml += tot;
				pivi +=jmlpv;
            }

        }
		
		$('#intpv').val(pivi);
		
        if($("#chkBox20").attr('checked') == true)
		{
			$('#intjumlah2').val(jml);
			var jml = parseInt($('#intjumlah2').val());
			var disc = 20;
			var komisi = (jml * disc) / 100;
			$('#komisi2').val(komisi);
			
		} else if ($("#chkBox10").attr('checked') == true)
		{
            $('#intjumlah1').val(jml);
			var jml = parseInt($('#intjumlah1').val());
			var disc = 10;
			var komisi = (jml * disc) / 100;
			$('#komisi1').val(komisi);
			
		} else if ($("#chkBoxFree").attr('checked') == true)
		{
			var disc = 10;
			var komisi = (jml * disc) / 100;
			$('#komisi1').val(komisi);
			
		} else {
			$('#intjumlah2').val(jml);
			var jml = parseInt($('#intjumlah2').val());
			var disc = 20;
			var komisi = (jml * disc) / 100;
			$('#komisi2').val(komisi);
			$('#komisi1').val(0);
			
		}
		//$('#intjumlah').val()= $('#intjumlah1').val()+$('#intjumlah2').val();

        if($('#komisi1').val() == ""){
            var kom1 = 0;
        }else{
            var kom1 = parseInt($('#komisi1').val());
        }
        if($('#komisi2').val() == ""){
            var kom2 = 0;
        }else{
            var kom2 = parseInt($('#komisi2').val());
        }
        if($('#intjumlah').val() == ""){
            var intjum = 0;
        }else{
            var intjum = parseInt($('#intjumlah').val());
        }

         if($('#intjumlah1').val() == ""){
            var intjum1 = 0;
         }else{
             var intjum1 = parseInt($('#intjumlah1').val());
         }
         if($('#intjumlah2').val() == ""){
            var intjum2 = 0;
         }else{
             var intjum2 = parseInt($('#intjumlah2').val());
         }

		var omset = intjum1 + intjum2;
		
		$('#intjumlah').val(omset);
		
		var totals = omset - kom1 - kom2;
        
        $('#totalbayar').val(totals);
    }

    $('#btnAdd').click(function(){
        $('#ButtonAdd').html($('#inputBrg').html());
    })

    function auto(){
        //alert(this.value);
        $(".id1").autocomplete({
            minLength: 2,
            source:
                function(req, add){
                $.ajax({
                    url: "<?php echo base_url(); ?>admin/penjualan/lookupBarang",
                    dataType: 'json',
                    type: 'POST',
                    data: req,
                    success:
                        function(data){
                        if(data.response =="true"){
                            add(data.message);
                        }
                    },
                });
            },
            select:
                function(event, ui) {
                $("#result1").append(
                "<input type='text' id='id_barang' name='id_barang' value='" + ui.item.value1 + "' size='15' /><input type='hidden' id='id_barang' name='id_barang' value='" + ui.item.id + "' size='15' /><input type='hidden' id='pv' name='pv' value='" + ui.item.value2 + "' size='15' />"
            );
            },
        });

    }


//check the checkbox
     $("#chkBoxTrade").click(function(){
     tradein();
        if($("#chkBoxTrade").attr('checked') == true){
            $(".frees").attr("disabled","");
			$("#komisitrade").attr("disabled","");
			
		}else if($("#chkBoxTrade").attr('checked') == false){
			document.frmjual.komisitrade.disabled = true;
        }
    });

    $("#chkBox20").click(function(){
        autoComp();
        if($("#chkBox20").attr('checked') == true){
			$(".frees").attr("disabled","");
			$("#txtpromo20").attr("disabled","");
		} else if($("#chkBox20").attr('checked') == false){
			$(".frees").attr("disabled","");
			$("#txtpromo20").attr("disabled","disabled");
		}
    });
	
	$("#chkBox10").click(function(){
        autoCompPromo10();
        if($("#chkBox10").attr('checked') == true){
			$(".frees").attr("disabled","");
			$("#txtpromo10").attr("disabled","");
		} else if($("#chkBox10").attr('checked') == false){
			$(".frees").attr("disabled","");
			$("#txtpromo10").attr("disabled","disabled");
		}
    });
	
	$("#chkBoxFreeHut").click(function(){
        hut();
        if($("#chkBoxFreeHut").attr('checked') == true){
			$(".frees").attr("disabled","");
			$("#txtfreehut").attr("disabled","");
		} else if($("#chkBoxFreeHut").attr('checked') == false){
			$(".frees").attr("disabled","");
			$("#txtfreehut").attr("disabled","disabled");
		}
    });
	
	$("#chkBoxFree").click(function(){
        satufreesatu();
        if($("#chkBoxFree").attr('checked') == true){
			$(".frees").attr("disabled","");
			$("#txtfree").attr("disabled","");
		} else if($("#chkBoxFree").attr('checked') == false){
			$(".frees").attr("disabled","");
			$("#txtfree").attr("disabled","disabled");
		}
    });


function hut(){
           $(".id1").autocomplete({
				minLength: 1,
                source:
                    function(req, add){
                    $.ajax({
                        url: "<?php echo base_url(); ?>admin/penjualan/lookupBarang",
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result1").html(
                     "<input type='text' id='harga_barang' name='harga_barang' value='" + ui.item.value1 + "' size='15' /><input type='hidden' id='id_barang' name='id_barang' value='" + ui.item.id + "' size='15' /><input type='hidden' id='pv' name='pv' value='" + ui.item.value2 + "' size='15' />"
                );
                },
            });
     
     $(".frees").autocomplete({
                minLength: 2,
                source:
                    function(req, add){

                    //alert(add);
                    $.ajax({
                        url: "<?php echo base_url(); ?>admin/penjualan/lookupBarang",
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result2").html(
                   "<input type='text' id='harga_barang_free' name='harga_barang_free' value='" + ui.item.value1 + "' size='15' /><input type='hidden' id='id_free' name='id_free' value='" + ui.item.id + "' size='15' />"
                );
                },
            });

}

function tradein(){
     if($("#chkBoxTrade").attr('checked') == false){
                var ur = "<?php echo base_url(); ?>admin/penjualan/lookupBarang";
            }else if ($("#chkBoxTrade").attr('checked') == true) {

                var ur = "<?php echo base_url(); ?>admin/penjualan/lookupBarangPromo20";
            }
            
           $(".id1").autocomplete({
				minLength: 1,
                source:
                    function(req, add){
                    $.ajax({
                        url: ur,
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result1").html(
                     "<input type='text' id='harga_barang' name='harga_barang' value='" + ui.item.value1 + "' size='15' /><input type='hidden' id='id_barang' name='id_barang' value='" + ui.item.id + "' size='15' /><input type='hidden' id='pv' name='pv' value='" + ui.item.value2 + "' size='15' />"
                );
                },
            });

	
	$(".frees").autocomplete({
                minLength: 2,
                source:
                    function(req, add){

                    //alert(add);
                    $.ajax({
                        url: "<?php echo base_url(); ?>admin/penjualan/lookupBarang",
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result2").html(
                   "<input type='text' id='harga_barang_free' name='harga_barang_free' value='" + ui.item.value1 + "' size='15' /><input type='hidden' id='id_free' name='id_free' value='" + ui.item.id + "' size='15' />"
                );
                },
            });

}

function satufreesatu(){

            if($("#chkBoxFree").attr('checked') == false){
                var ur = "<?php echo base_url(); ?>admin/penjualan/lookupBarang";
            }else if ($("#chkBoxFree").attr('checked') == true) {

                var ur = "<?php echo base_url(); ?>admin/penjualan/lookupBarangPromo10";
            }
            
           $(".id1").autocomplete({
				minLength: 1,
                source:
                    function(req, add){
                    $.ajax({
                        url: ur,
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result1").html(
                     "<input type='text' id='harga_barang' name='harga_barang' value='" + ui.item.value1 + "' size='15' /><input type='hidden' id='id_barang' name='id_barang' value='" + ui.item.id + "' size='15' /><input type='hidden' id='pv' name='pv' value='" + ui.item.value2 + "' size='15' />"
                );
                },
            });
			
			$(".frees").autocomplete({
                minLength: 2,
                source:
                    function(req, add){

                    //alert(add);
                    $.ajax({
                        url: "<?php echo base_url(); ?>admin/penjualan/lookupBarang",
                        dataType: 'json',
                        type: 'POST',
                        data: req,
                        success:
                            function(data){
                            if(data.response =="true"){
                                add(data.message);
                            }
                        },
                    });
                },
                select:
                    function(event, ui) {
                    $("#result2").html(
                   "<input type='text' id='harga_barang_free' name='harga_barang_free' value='" + ui.item.value1 + "' size='15' /><input type='hidden' id='id_free' name='id_free' value='" + ui.item.id + "' size='15' />"
                );
                },
            });

			
}

$('#intid_jpenjualan').change(function()
{
   if ($(this).attr('value')== 1)
   	{
		var title = "Nota Penjualan Reguler";
		$("#title").text(title);
		$("#komisitrade").attr("disabled","disabled");
	} else  if ($(this).attr('value')== 2)
   	{
		var title = "Nota Penjualan Hut";
		$("#title").text(title);
		$("#komisitrade").attr("disabled","disabled");
	} else  if ($(this).attr('value')== 3)
   	{
		var title = "Nota Penjualan Challenge";
		$("#title").text(title);
		$("#komisitrade").attr("disabled","disabled");
	} else  if ($(this).attr('value')== 4)
   	{
		var title = "Nota Penjualan Trade In";
		$("#title").text(title);
		$("#komisitrade").attr("disabled","");
	} else  if ($(this).attr('value')== 5)
   	{
		var title = "Nota Penjualan 1 Free 1 Hut";
		$("#title").text(title);
		$("#komisitrade").attr("disabled","disabled");
	} else  if ($(this).attr('value')== 6)
   	{
		var title = "Nota Penjualan 1 Free 1";
		$("#title").text(title);
		$("#komisitrade").attr("disabled","disabled");
	} else  if ($(this).attr('value')== 7)
   	{
		var title = "Nota Penjualan Netto";
		$("#title").text(title);
		$("#komisitrade").attr("disabled","");
	} 
   
	
});
</script>

